﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using CoDbObject;

namespace Colligate.DataSource.DriverTraining.Sys.Organization
{
    class SystemOrgSchool : BaseLegoModule
    {
        private const string TABLE_SCHOOL_INFO = "SystemOrgSchool";

        public SystemOrgSchool(IDataSourceLayer dataLayer)
            : base(new string[] { TABLE_SCHOOL_INFO }, dataLayer)
        {
        }

        #region 返回Lego模块涉及到的数据名称的结构信息
        /// <summary>
        /// 返回Lego模块涉及到的数据名称的结构信息
        /// </summary>
        /// <param name="strDataName">基础表名称</param>
        /// <returns>表结构信息</returns>
        override public IFieldInfo[] GetStructInfo(string strDataName)
        {
            // 建立IFieldInfo列表
            // CFieldInfo(字段名, 类型, 长度, 索引, 状态, 字段说明, 字段帮助, 显示的格式化字符串, 字段宽度, 关联记录)
            // 类型： text，byte，short，long，single，double，currency，date，logical，memo，binary
            // 索引： 0 无索引，1 重复索引，2 唯一索引，3 关键字段
            // 状态： 0 系统字段，>1显示信息的字段， 2 用于标识记录名称的字段

            IFieldInfo[] tableStructInfo;
            switch (strDataName)
            {
                case TABLE_SCHOOL_INFO:	 // 驾校基本信息
                    tableStructInfo = new IFieldInfo[8];
                    tableStructInfo[0] = new CFieldInfo("fSchoolGuid", "text", 36, 2, 0, "驾校信息", "驾校信息", "", 52, 0);
                    tableStructInfo[1] = new CFieldInfo("fSchoolName", "text", 50, 0, 1, "驾校名称，简称", "驾校名称，简称", "", 52, 0);
                    tableStructInfo[2] = new CFieldInfo("fSchoolFullName", "text", 100, 0, 1, "驾校全称", "驾校全称", "", 52, 0);
                    tableStructInfo[3] = new CFieldInfo("fInChargeOf", "text", 20, 0, 1, "负责人姓名", "负责人姓名", "", 52, 0);
                    tableStructInfo[4] = new CFieldInfo("fEconomicType", "text", 20, 0, 1, "经济类型", "经济类型", "", 52, 0);
                    tableStructInfo[5] = new CFieldInfo("fTelephone", "text", 20, 0, 1, "电话", "电话", "", 52, 0);
                    tableStructInfo[6] = new CFieldInfo("fSchoolAddress", "text", 200, 0, 1, "经营地址", "经营地址", "", 52, 0);
                    tableStructInfo[7] = new CFieldInfo("fZipCode", "text", 6, 0, 1, "邮编", "邮编", "", 52, 0);
                    break;
                default: tableStructInfo = null; break;
            }
            return tableStructInfo;
        }
        #endregion

        #region 驾校信息
        public IDBDataObject GetSchoolInfoData(string strDataGuid)
        {
            string tableName = GetStructGlobalName(TABLE_SCHOOL_INFO);
            return DataLayer.GetDBDataObject(tableName, string.Format("fSchoolGuid = '{0}'", strDataGuid));
        }

        /// <summary>
        /// 通过查询过滤条件取得教练信息
        /// </summary>
        /// <param name="queryFilter">查询过滤表达式</param>
        /// <returns></returns>
        public IDBBigObjectSet GetSchoolList(string queryFilter)
        {
            return DataLayer.GetDBBigObjectSet(GetStructGlobalName(TABLE_SCHOOL_INFO), queryFilter, "fSchoolName");
        }
        #endregion
    }
}
